import { sessionStorage } from "@/utils/storage";
import { showToast } from "vant";

export default {
    //获取token
    getToken() {
        return sessionStorage.get('Token') || '';
    },
    //判断是否登录
    checkLogin(jumpLogin = true) {
        if (this.getToken()) {
            return true;
        } else {
            if (jumpLogin) {
                const router = useRouter()
                showToast({
                    message: '未登录',
                    duration: 2000,
                    onClose: () => {
                        router.push({ path: '/login' })
                    }
                })
            }
            return false;
        }
    },
    //登录
    doLogin(data: object) {
        sessionStorage.set('Token', data['access_token'])
        // sessionStorage.set('auth_expire_at', data['auth_expire_at'])
    },
    //退出登录
    doLogout() {
        sessionStorage.remove('Token')
    }
}
